﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.Objects.DataClasses;

namespace ImmovablesManager
{
    /// <summary>
    /// Interaction logic for NewFlatCard.xaml
    /// </summary>
    public partial class NewFlatCard : Window
    {
        private Guid _realtorId;
        private bool _isEdit;
        private Guid _newFlatId;
        private Guid _userId;
        private Guid _newFlatNewGuid;

        public NewFlatCard()
        {
            InitializeComponent();
        }

        public NewFlatCard(Guid newFlatId, bool editFag)
        {
            InitializeComponent();

            _realtorId = Login.UserId;
            var currentRealtoNamer = Login.UserName;
            TBxRealtor.Text = currentRealtoNamer;
            TBxRealtor.IsReadOnly = true;

            foreach (var region in AppController.ImmoRepository.GetAllRegions())
            {
                ComboboxRegion.Items.Add(new ComboBoxItem() { Content = region.RegionName, Tag = region.RegionId });//, Name = region.RegionId.ToString()});
            };
            ComboboxRegion.SelectedIndex = 0;

            foreach (var flatType in AppController.ImmoRepository.GetAllFlatType())
            {
                ComboFlatType.Items.Add(new ComboBoxItem() { Content = flatType.FlatTypeName, Tag = flatType.FlatTypeId });
            }
            ComboFlatType.SelectedIndex = 0;

            foreach (var typeWC in AppController.ImmoRepository.GetAllWCType())
            {
                CmbBxWC.Items.Add(new ComboBoxItem() { Content = typeWC.WCTypeName, Tag = typeWC.WCId });
            }
            CmbBxWC.SelectedIndex = 0;

            foreach (var balconType in AppController.ImmoRepository.GetAllBalconType())
            {
                CmbBoxBalcon.Items.Add(new ComboBoxItem() { Content = balconType.BalconTypeName, Tag = balconType.BalconTypeId });
            }
            CmbBoxBalcon.SelectedIndex = 0;

            foreach (var typeWall in AppController.ImmoRepository.GetAllHouseMaterial())
            {
                CmbBxWallsMaterial.Items.Add(new ComboBoxItem() { Content = typeWall.HouseMaterialName, Tag = typeWall.HouseMaterialId });
            }
            CmbBxWallsMaterial.SelectedIndex = 0;

            FinDateDate.SelectedDate = DateTime.Now;
            //TBxBuildingStageDate.Text = DateTime.Now.AddYears(3).Month.ToString() + " " + DateTime.Now.AddYears(3).Year.ToString();  //DateTime.Now.Date.ToString();
            TBxShowTime.Text = DateTime.Now.Date.ToString();

            _isEdit = editFag;

            _userId = Login.UserId;

            if (_isEdit)
            {
                _newFlatId = newFlatId;
                FillField(_newFlatId);
                _newFlatNewGuid = AddNewFlat(false);
            }


        }

        public void AddRecordChangingStory(string operation, string value, string oldValue, string state, string number)
        {
            AppController.ImmoRepository.AddChangingStory(operation, _newFlatId, value, oldValue, _userId, state, number);
        }

        public Guid AddNewFlat(bool IsShown)
        {


            Guid ownerId = AppController.ImmoRepository.AddOwner(TBxPhone.Text, TBxPhone.Text, TBxOwnerFIO.Text);

            Guid finDataId = AppController.ImmoRepository.AddFinancialData(FinDateDate.SelectedDate, double.Parse(TBxClientCost.Text),
                                                           double.Parse(TBxCostWithUs.Text),
                                                           _realtorId, TBxContractNumber.Text, "");

            string newFlatFacing = Convert.ToInt32(checkBox1.IsChecked.Value).ToString() + Convert.ToInt32(checkBox2.IsChecked.Value).ToString() +
                                    Convert.ToInt32(checkBox3.IsChecked.Value).ToString() + Convert.ToInt32(checkBox4.IsChecked.Value).ToString() +
                                    Convert.ToInt32(checkBox5.IsChecked.Value).ToString() +
                                    Convert.ToInt32(checkBox6.IsChecked.Value).ToString() + Convert.ToInt32(checkBox7.IsChecked.Value).ToString() +
                                    Convert.ToInt32(checkBox8.IsChecked.Value).ToString() + Convert.ToInt32(checkBox9.IsChecked.Value).ToString() +
                                    Convert.ToInt32(checkBox10.IsChecked.Value).ToString() + Convert.ToInt32(checkBox11.IsChecked.Value).ToString() +
                                    Convert.ToInt32(checkBox12.IsChecked.Value).ToString();


            Guid currentBalconType = (Guid)((ComboBoxItem)CmbBoxBalcon.SelectedItem).Tag;
            Guid currentFlatType = (Guid)((ComboBoxItem)ComboFlatType.SelectedItem).Tag;
            Guid currentWCType = (Guid)((ComboBoxItem)CmbBxWC.SelectedItem).Tag;
            Guid currentRegion = (Guid)((ComboBoxItem)ComboboxRegion.SelectedItem).Tag;
            int roomCount = int.Parse(((ComboBoxItem)CmbBoxRoomCount.SelectedItem).Tag.ToString());
            Guid materialWalls = (Guid)((ComboBoxItem)CmbBxWallsMaterial.SelectedItem).Tag;
            double costForMetr = double.Parse(TBxCostWithUs.Text) / double.Parse(TBxTotalArea.Text);


            var newFlatId = AppController.ImmoRepository.AddNewFlat(TBxAdditionalInfo.Text, TextBoxnewFlatAddress.Text,
                                                     currentBalconType,
                                                     TBxBuildingFinishedDate.Text,
                                                     costForMetr,
                                                     TBxDocuments.Text,
                                                     "", TBxFloor.Value,
                                                     TBxFloorsCount.Value,
                                                     finDataId, double.Parse(TBxTotalArea.Text),
                                                     double.Parse(TBxLivingArea.Text),
                                                     double.Parse(TBxKitchen.Text),
                                                     materialWalls,
                                                     TextBoxNewFlatName.Text, TBxBuilder.Text, "", ownerId,
                                                     roomCount,
                                                     CmbBxSellForm.Text, TBxShowCondition.Text,
                                                     DateTime.Parse(TBxShowTime.Text),
                                                     TBxBuildingStage.Text,
                                                     currentFlatType,
                                                     "", currentWCType,
                                                     TBxWindows.Text, TBxInfoForSellerContact.Text,
                                                     currentRegion,
                                                     TextBoxNearest.Text, double.Parse(TBxCostWithUs.Text),
                                                     RadioBlack.IsChecked, newFlatFacing, ChckBxAjoinment.IsChecked,
                                                     IsShown); //Здесь добавим карточку, которая будет отлична от такой же добавленной при редактировании за счет этого последнего флага

            if (IsShown)
            {
                AddRecordChangingStory("Создание карточки новостройки", "", "", "add",
                                       AppController.ImmoRepository.GetFinancialDataById(finDataId).
                                           FinancialDataCardNumber.ToString());
            }
            return newFlatId;
        }


        public void EditNewFlat(Guid currentNewFlatGuid)
        {

            var flat = AppController.ImmoRepository.GetNewFlatById(currentNewFlatGuid);

            Guid currentBalconType = (Guid)((ComboBoxItem)CmbBoxBalcon.SelectedItem).Tag;
            string currentBalconTypeStr = (string)((ComboBoxItem)CmbBoxBalcon.SelectedItem).Content;
            Guid currentFlatType = (Guid)((ComboBoxItem)ComboFlatType.SelectedItem).Tag;
            string currentFlatTypeStr = (string)((ComboBoxItem)ComboFlatType.SelectedItem).Content;
            Guid currentWCType = (Guid)((ComboBoxItem)CmbBxWC.SelectedItem).Tag;
            string currentWCTypeStr = (string)((ComboBoxItem)CmbBxWC.SelectedItem).Content;
            Guid currentRegion = (Guid)((ComboBoxItem)ComboboxRegion.SelectedItem).Tag;
            int roomCount = int.Parse(((ComboBoxItem)CmbBoxRoomCount.SelectedItem).Tag.ToString());
            string currentRegionStr = (string)((ComboBoxItem)ComboboxRegion.SelectedItem).Content;
            Guid materialWalls = (Guid)((ComboBoxItem)CmbBxWallsMaterial.SelectedItem).Tag;
            string materialWallsStr = (string)((ComboBoxItem)CmbBxWallsMaterial.SelectedItem).Content;
            double costForMetr = double.Parse(TBxCostWithUs.Text) / double.Parse(TBxTotalArea.Text);
            string newFlatFacing = Convert.ToInt32(checkBox1.IsChecked.Value).ToString() + Convert.ToInt32(checkBox2.IsChecked.Value).ToString() +
                                    Convert.ToInt32(checkBox3.IsChecked.Value).ToString() + Convert.ToInt32(checkBox4.IsChecked.Value).ToString() +
                                    Convert.ToInt32(checkBox5.IsChecked.Value).ToString() +
                                    Convert.ToInt32(checkBox6.IsChecked.Value).ToString() + Convert.ToInt32(checkBox7.IsChecked.Value).ToString() +
                                    Convert.ToInt32(checkBox8.IsChecked.Value).ToString() + Convert.ToInt32(checkBox9.IsChecked.Value).ToString() +
                                    Convert.ToInt32(checkBox10.IsChecked.Value).ToString() + Convert.ToInt32(checkBox11.IsChecked.Value).ToString() +
                                    Convert.ToInt32(checkBox12.IsChecked.Value).ToString();


            // запись в историю
            string number = flat.FinancialData.FinancialDataCardNumber.ToString();
            AddRecordChangingStory("Начало редактирования карточки", "", "", "edit", number);

            if (currentFlatType != flat.NewFlatTypeId) AddRecordChangingStory("Изменение типа квартиры", currentFlatTypeStr, flat.FlatType.FlatTypeName, "edit field", number);
            if (currentBalconType != flat.NewFlatBalconTypeId) AddRecordChangingStory("Изменение поля <балкон/лоджия>", currentBalconTypeStr, flat.BalconType.BalconTypeName, "edit field", number);
            if (currentWCType != flat.NewFlatWCId) AddRecordChangingStory("Изменение поля <Санузел>", currentWCTypeStr, flat.WCType.WCTypeName, "edit field", number);
            if (currentRegion != flat.NewFlatObjectRegionId) AddRecordChangingStory("Изменение поля <район>", currentRegionStr, flat.Region.RegionName, "edit field", number);
            if (roomCount != flat.NewFlatRoomsCount) AddRecordChangingStory("Изменение поля <Количество комнат>", roomCount.ToString(), flat.NewFlatRoomsCount.ToString(), "edit field", number);
            if (materialWalls != flat.NewFlatHouseMaterialId) AddRecordChangingStory("Изменение поля <Материал стен>", materialWallsStr, flat.HouseMaterial.HouseMaterialName, "edit field", number);
            if (TBxTotalArea.Text != flat.NewFlatTotalArea.ToString()) AddRecordChangingStory("Изменение поля <Общая площадь>", TBxTotalArea.Text, flat.NewFlatTotalArea.ToString(), "edit field", number);
            if (TBxLivingArea.Text != flat.NewFlatLivingArea.ToString()) AddRecordChangingStory("Изменение поля <Жилая площадь>", TBxLivingArea.Text, flat.NewFlatLivingArea.ToString(), "edit field", number);
            if (TBxKitchen.Text != flat.NewFlatKitchenArea.ToString()) AddRecordChangingStory("Изменение поля <Площадь кухни>", TBxKitchen.Text, flat.NewFlatKitchenArea.ToString(), "edit field", number);
            // if (newFlatFacing != flat.NewFlatFacing) AddRecordChangingStory("Изменение поля <Отделка>", flat.NewFlatLivingArea.ToString());
            if (TBxPhone.Text != flat.Owner.OwnerMobilePhone) AddRecordChangingStory("Изменение поля <Номер телефона владельца>", TBxPhone.Text, flat.Owner.OwnerMobilePhone, "edit field", number);
            if (TBxAdditionalInfo.Text != flat.NewFlatAdditionalInfo) AddRecordChangingStory("Изменение поля <Дополнительные сведения>", TBxAdditionalInfo.Text, flat.NewFlatAdditionalInfo, "edit field", number);
            if (TextBoxnewFlatAddress.Text != flat.NewFlatAddress) AddRecordChangingStory("Изменение поля <Адрес>", TextBoxnewFlatAddress.Text, flat.NewFlatAddress, "edit field", number);
            if (TBxDocuments.Text != flat.NewFlatDocuments) AddRecordChangingStory("Изменение поля <Документы>", TBxDocuments.Text, flat.NewFlatDocuments, "edit field", number);
            if (TextBoxNewFlatName.Text != flat.NewFlatObject) AddRecordChangingStory("Изменение поля <Наименование>", TextBoxNewFlatName.Text, flat.NewFlatObject, "edit field", number);
            if (TBxBuilder.Text != flat.NewFlatObjectBuilder) AddRecordChangingStory("Изменение поля <Застройщик>", TBxBuilder.Text, flat.NewFlatObjectBuilder, "edit field", number);
            if (CmbBxSellForm.Text != flat.NewFlatSellForm) AddRecordChangingStory("Изменение поля <Форма продажи>", CmbBxSellForm.Text, flat.NewFlatSellForm, "edit field", number);
            if (TBxShowCondition.Text != flat.NewFlatShowTerms) AddRecordChangingStory("Изменение поля <Условия показа>", TBxShowCondition.Text, flat.NewFlatShowTerms, "edit field", number);
            if (DateTime.Parse(TBxShowTime.Text) != flat.NewFlatShowTime) AddRecordChangingStory("Изменение поля <Время показа>", TBxShowTime.Text, flat.NewFlatShowTime.ToString(), "edit field", number);
            if (TBxBuildingFinishedDate.Text != flat.NewFlatBuildingFinishedDate) AddRecordChangingStory("Изменение поля <Дата сдачи строительства>", TBxBuildingFinishedDate.Text, flat.NewFlatBuildingFinishedDate, "edit field", number);
            if (TBxWindows.Text != flat.NewFlatWindowsView) AddRecordChangingStory("Изменение поля <Куда выходят окна>", TBxWindows.Text, flat.NewFlatWindowsView, "edit field", number);
            if (TBxInfoForSellerContact.Text != flat.NewFlatInfoForContactsWithSellers) AddRecordChangingStory("Изменение поля <Информация(при контактах с продавцами)>", TBxInfoForSellerContact.Text, flat.NewFlatInfoForContactsWithSellers, "edit field", number);
            if (TextBoxNearest.Text != flat.NewFlatObjectNearestSign) AddRecordChangingStory("Изменение поля <Ближайшие ориентиры>", TextBoxNearest.Text, flat.NewFlatObjectNearestSign, "edit field", number);
            if (TBxCostWithUs.Text != flat.FinancialData.FinancialDataPriceWithUs.ToString()) AddRecordChangingStory("Изменение поля <Цена с нами>", TBxCostWithUs.Text, flat.FinancialData.FinancialDataPriceWithUs.ToString(), "edit field", number);
            if (RadioBlack.IsChecked != flat.NewFlatFacingTypeBlack) AddRecordChangingStory("Изменение поля <Отделка(черновая)>", RadioBlack.IsChecked.ToString(), flat.NewFlatFacingTypeBlack.ToString(), "edit field", number);
            if (ChckBxAjoinment.IsChecked != flat.NewFlatAjoiningRoom) AddRecordChangingStory("Изменение поля <Планировка комнат(смежные)>", ChckBxAjoinment.IsChecked.ToString(), flat.NewFlatAjoiningRoom.ToString(), "edit field", number);


            Guid ownerId = flat.NewFlatOwnerId;
            Guid finDataId = flat.NewFlatFinancialDataId;

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //var newFlatNewId = AppController.ImmoRepository.AddNewFlat();

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

            AppController.ImmoRepository.EditFinancialData(finDataId, FinDateDate.SelectedDate, double.Parse(TBxClientCost.Text),
                                                           double.Parse(TBxCostWithUs.Text),
                                                           _realtorId, TBxContractNumber.Text,"");
            AppController.ImmoRepository.EditOwner(ownerId, TBxPhone.Text, TBxPhone.Text, TBxOwnerFIO.Text);

            AppController.ImmoRepository.EditNewFlat(currentNewFlatGuid, TBxAdditionalInfo.Text, TextBoxnewFlatAddress.Text,
                                                     currentBalconType,
                                                     TBxBuildingStage.Text,
                                                     costForMetr,
                                                     TBxDocuments.Text,
                                                     "", TBxFloor.Value, TBxFloorsCount.Value,
                                                     finDataId, double.Parse(TBxTotalArea.Text),
                                                     double.Parse(TBxLivingArea.Text),
                                                     double.Parse(TBxKitchen.Text),
                                                     materialWalls,
                                                     TextBoxNewFlatName.Text, TBxBuilder.Text, "", ownerId,
                                                     roomCount,
                                                     CmbBxSellForm.Text, TBxShowCondition.Text,
                                                     DateTime.Parse(TBxShowTime.Text),
                                                     TBxBuildingFinishedDate.Text,
                                                     currentFlatType,
                                                     "", currentWCType,
                                                     TBxWindows.Text, TBxInfoForSellerContact.Text,
                                                     currentRegion,
                                                     TextBoxNearest.Text, double.Parse(TBxCostWithUs.Text),
                                                     RadioBlack.IsChecked, newFlatFacing, ChckBxAjoinment.IsChecked,
                                                     _newFlatNewGuid);

            AddRecordChangingStory("Окончание редактирования карточки новостройки", "", "", "edit", number);
        }


        public void FillField(Guid currentNewFlatGuid)
        {
            var flat = AppController.ImmoRepository.GetNewFlatById(currentNewFlatGuid);
            Owner owner = flat.Owner;
            FinancialData finData = flat.FinancialData;

            CardNumberTBx.Text = finData.FinancialDataCardNumber.ToString();

            if (finData.FinancialDataDate != null) FinDateDate.DisplayDate = (DateTime)finData.FinancialDataDate;
            TBxBuildingStage.Text = flat.NewFlatBuildingStage;

            TBxClientCost.Text = flat.NewFlatTotalCost.ToString();
            TBxCostWithUs.Text = finData.FinancialDataPriceWithUs.ToString();
            TBxContractNumber.Text = finData.FnancialDataContract;
            TBxPhone.Text = owner.OwnerMobilePhone;
            TBxOwnerFIO.Text = owner.OwnerName;

            TBxAdditionalInfo.Text = flat.NewFlatAdditionalInfo;
            TextBoxnewFlatAddress.Text = flat.NewFlatAddress;
            TBxDocuments.Text = flat.NewFlatDocuments;
            TBxFloorsCount.Value = flat.NewFlatFloorsCount;
            TBxFloor.Value = flat.NewFlatFloor;
            TBxTotalArea.Text = flat.NewFlatTotalArea.ToString();
            TBxLivingArea.Text = flat.NewFlatLivingArea.ToString();
            TBxKitchen.Text = flat.NewFlatKitchenArea.ToString();
            TextBoxNewFlatName.Text = flat.NewFlatObject;
            TBxBuilder.Text = flat.NewFlatObjectBuilder;
            CmbBxSellForm.Text = flat.NewFlatSellForm;
            TBxShowCondition.Text = flat.NewFlatShowTerms;
            TBxShowTime.Text = (flat.NewFlatShowTime is DateTime ? (DateTime)flat.NewFlatShowTime : new DateTime()).Date.ToString();
            TBxBuildingFinishedDate.Text = flat.NewFlatBuildingFinishedDate;
            TBxWindows.Text = flat.NewFlatWindowsView;
            TBxInfoForSellerContact.Text = flat.NewFlatInfoForContactsWithSellers;
            TextBoxNearest.Text = flat.NewFlatObjectNearestSign;
            RadioBlack.IsChecked = flat.NewFlatFacingTypeBlack;
            if ((bool)!flat.NewFlatFacingTypeBlack) RadioWhite.IsChecked = true;
            ChckBxAjoinment.IsChecked = flat.NewFlatAjoiningRoom;


            FillComboBox(CmbBoxBalcon, flat.NewFlatBalconTypeId);
            FillComboBox(ComboFlatType, flat.NewFlatTypeId);
            FillComboBox(CmbBxWC, flat.NewFlatWCId);
            FillComboBox(ComboboxRegion, flat.NewFlatObjectRegionId);
            CmbBoxRoomCount.SelectedIndex = (int)flat.NewFlatRoomsCount - 1;
            FillComboBox(CmbBxWallsMaterial, flat.NewFlatHouseMaterialId);



            checkBox1.IsChecked = Convert.ToBoolean(int.Parse(flat.NewFlatFacing.ToCharArray()[0].ToString()));
            checkBox2.IsChecked = Convert.ToBoolean(int.Parse(flat.NewFlatFacing.ToCharArray()[1].ToString()));
            checkBox3.IsChecked = Convert.ToBoolean(int.Parse(flat.NewFlatFacing.ToCharArray()[2].ToString()));
            checkBox4.IsChecked = Convert.ToBoolean(int.Parse(flat.NewFlatFacing.ToCharArray()[3].ToString()));
            checkBox5.IsChecked = Convert.ToBoolean(int.Parse(flat.NewFlatFacing.ToCharArray()[4].ToString()));
            checkBox6.IsChecked = Convert.ToBoolean(int.Parse(flat.NewFlatFacing.ToCharArray()[5].ToString()));
            checkBox7.IsChecked = Convert.ToBoolean(int.Parse(flat.NewFlatFacing.ToCharArray()[6].ToString()));
            checkBox8.IsChecked = Convert.ToBoolean(int.Parse(flat.NewFlatFacing.ToCharArray()[7].ToString()));
            checkBox9.IsChecked = Convert.ToBoolean(int.Parse(flat.NewFlatFacing.ToCharArray()[8].ToString()));
            checkBox10.IsChecked = Convert.ToBoolean(int.Parse(flat.NewFlatFacing.ToCharArray()[9].ToString()));
            checkBox11.IsChecked = Convert.ToBoolean(int.Parse(flat.NewFlatFacing.ToCharArray()[10].ToString()));
            checkBox12.IsChecked = Convert.ToBoolean(int.Parse(flat.NewFlatFacing.ToCharArray()[11].ToString()));
        }


        public void FillComboBox(ComboBox comboBox, Guid tag)
        {
            foreach (var item in comboBox.Items)
            {
                var it = item as ComboBoxItem;
                if (Guid.Parse(it.Tag.ToString()) == tag)
                {
                    comboBox.SelectedIndex = comboBox.Items.IndexOf(it);
                }
            }
        }

        private void BTnCancel_Click(object sender, RoutedEventArgs e)
        {
            AppController.ImmoRepository.DeleteNewFlat(_newFlatNewGuid);
            Close();
        }

        private void BTnOk_Click(object sender, RoutedEventArgs e)
        {
            if (!_isEdit)
            {
                AddNewFlat(true);
            }
            else
            {
                EditNewFlat(_newFlatId);
            }
            Close();
        }

        private void BtnAccept_Click(object sender, RoutedEventArgs e)
        {
            AppController.ImmoRepository.AcceptNewFlat(_newFlatId, true);

            var newFlat = AppController.ImmoRepository.GetNewFlatById(_newFlatId);

            if ((newFlat.NewFlatNewId) == null
                & ((bool)newFlat.NewFlatIsShown)) //Была добавлена
            {
                //Все уже сделано! Для различия добавленно записи и редактируемой хватает только хвостового guid, а для различия
                //с хвостовой записью нужен еще флаг IsShown
            }
            else
            {
                AppController.ImmoRepository.DeleteNewFlat(newFlat.NewFlatNewId); //Удаляем главную запись
                AppController.ImmoRepository.BreakNewFlatNewId(newFlat.NewFlatId);
                AppController.ImmoRepository.SetShownNewFlat(newFlat.NewFlatId, true); //Делаем дочернюю запись главной
            }
            AppController.ImmoRepository.DeleteNewFlat(_newFlatNewGuid);

            Close();
        }

        private void BtnReject_Click(object sender, RoutedEventArgs e)
        {
            AppController.ImmoRepository.AcceptNewFlat(_newFlatId, false);
            var addedNewFlat = AppController.ImmoRepository.GetNewFlatById(_newFlatId);

            if (addedNewFlat.NewFlatNewId == null) //Была добавлена
            {
                AppController.ImmoRepository.DeleteNewFlat(_newFlatId);
            }
            else
            {
                AppController.ImmoRepository.DeleteNewFlat(addedNewFlat.NewFlatId);
                AppController.ImmoRepository.BreakNewFlatNewId(addedNewFlat.NewFlatNewId);
                AppController.ImmoRepository.SetShownNewFlat(addedNewFlat.NewFlatNewId, true);
            }

            AppController.ImmoRepository.DeleteNewFlat(_newFlatNewGuid);
            Close();
        }

        private void ShowMapBtn_Click(object sender, RoutedEventArgs e)
        {
            var map = new Map();
            if (map.Find(((ComboBoxItem)ComboboxRegion.SelectedItem).Content + " " + TextBoxnewFlatAddress.Text))
                map.ShowDialog();
            else
            {
                MessageBox.Show("Не удалось определить местоположение!", "Ошибка определения местоположения");
            }
        }
    }
}
